﻿@using System.Web.Script.Serialization
@using IAO.Common.Network.MessageImplementations.SCADA
@model DirectorPropertiesViewModel
@{
    ViewData["Title"] = "Service Properties";
}

<h2>System Service Properties</h2>

<p>Select a service to view its properties</p>

<form action="/" method="GET">
    @Html.DropDownList("servicesID", (SelectList) ViewBag.Services)
    <br/>
    <input type="submit" class="formSubmit" value="View"/>
</form>
    
<p>
    @{
        if (Model.SelectedServiceProperties != "null" && Model.SelectedServiceProperties != "None")
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            List<PropertyMessage> properties = serializer.Deserialize<List<PropertyMessage>>(Model.SelectedServiceProperties);

            <table class="propertiesTable">
                <thead><tr><td>Id</td><td>Class</td><td>Name</td><td>Type</td><td>Value</td><td>Readonly</td></tr></thead>
                @foreach (PropertyMessage property in properties)
                {
                    if (property.ReadOnly)
                    {
                        <tr><td>@property.Id</td><td>@property.Class</td><td>@property.Name</td><td>@property.Type</td><td>@property.Value</td><td>@property.ReadOnly</td></tr>
                    }
                    else
                    {
                        <tr><td>@property.Id</td><td>@property.Class</td><td>@property.Name</td><td>@property.Type</td><td>
                            @using (Html.BeginForm("SetProperty", "DirectorProperties", FormMethod.Post, new {id = $"propertyUpdateForm{property.Id}"}))
                            {
                                <input type="hidden" name="endpoint" , value="@Model.SelectedService" , id="endpoint@property.Id" />
                                <input type="hidden" name="propertyId", value="@property.Id", id="propertyId@property.Id"/>
                                <input type="text" name="propertyValue" value="@property.Value" id="propertyValue@property.Id"/>
                                <input type="submit" class="propertySubmit" value="Update"/>
                            }
                        </td><td>@property.ReadOnly</td></tr>
                    }
                }
            </table>
        }
        else
        {
            @Html.Raw("No Properties Returned<br/>");
        }
    }
</p>